/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.log.controller;

import cn.hutool.json.JSONObject;
import com.ai.AiParam;
import com.ai.PostDeepSeek;
import com.log.service.Service1;
import com.log.service.Service2;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * author: liubw
 * Controller
 */
@RestController
@RequestMapping("/api")
public class Controller {

    @Autowired
    private PostDeepSeek ds;
    @PostMapping("/seek")
    @ResponseBody
    public String talkToDeepSeek(@RequestBody AiParam param) {
        return ds.post(param.getContent());
    }

    @Autowired
    private Service1 service;

    @Autowired
    private Service2 service2;

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) throws Exception {
        service.doSomething("doSomething");
        return "Hello " + name;
    }

    @RequestMapping("/method2")
    @ResponseBody
    public String method2(@RequestParam(name = "name", defaultValue = "unknown user") String name) throws Exception {
        service2.method2();
        return "Hello " + name;
    }

    @GetMapping("/send")
    public String sendMessage() throws Exception {
        Map<String, Object> map = new HashMap<>();

        // 获取当前日期和时间
        LocalDateTime nowDateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateTimeFormatter.format(nowDateTime));
        map.put("server_time", dateTimeFormatter.format(nowDateTime));
        map.put("server_code", "200");
        map.put("server_message", "服务器推送到客户端");
        JSONObject jsonObject = new JSONObject(map);
//        WebSocketServer.sendAllMessage(redissionHelper.getLog());
        return jsonObject.toString();
    }

    @RequestMapping("/version")
    @ResponseBody
    public HashMap<String, Object> getVersion() throws Exception {
        String res = service.doSomething("222");
        HashMap<String, Object> result = new HashMap<>();
        result.put("version", "v0.3");
        return result;
    }
}
